﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Management.Automation;
using System.Management;

namespace HyperVSnapin.Helpers
{
    class VirtualMachineWMIHelper : GenericWMIHelper
    {
        /// <summary>
        /// Return all corresponding Virtual Machine on defined Host
        /// </summary>
        /// <param name="name">Name of the Virtual Machines to get. Support Wild Cards (*)</param>
        /// <param name="host">WMI Object on the Host</param>
        public List<System.Management.ManagementObject> GetVirtualMachines(string name, string host, PSCredential credentials)
        {
            return this.Query(
                "Msvm_ComputerSystem", 
                string.Format("Caption Like '%Virtual%' And ElementName Like '{0}' ", name.Replace('*', '%').Replace('?', '_')), 
                host, 
                credentials, 
                @"root\Virtualization");
        }

        /// <summary>
        /// Return a Virtual Machine with the exact name
        /// </summary>
        /// <param name="name">Name of VM to look for</param>
        /// <param name="host">WMI Object on the Host</param>
        public System.Management.ManagementObject GetVirtualMachine(string name, string host, PSCredential credentials)
        {
            throw new System.NotImplementedException();
        }

        /// <summary>
        /// Change the VM state
        /// </summary>
        /// <param name="vm">VM to change state</param>
        /// <param name="newState">New state</param>
        public void RequestStateChange(ManagementObject vm, int newState)
        {
            base.Invoke(vm, "RequestStateChange", new object[] { newState });
        }


    }
}
